﻿using System;
using UnityEngine;

// Token: 0x0200030F RID: 783
public class MicroObstacleDetector : ObstacleDetector
{
	// Token: 0x060013D7 RID: 5079 RVA: 0x000843EB File Offset: 0x000825EB
	private void Awake()
	{
		this.myTransform = base.transform;
	}

	// Token: 0x060013D8 RID: 5080 RVA: 0x000843FC File Offset: 0x000825FC
	public override bool CheckObstacle()
	{
		float time = Time.time;
		if (time > this.nextCheck)
		{
			this.obstacleDetected = this.DoRaycasts();
			this.nextCheck = time + this.timeBetweenChecks;
		}
		return this.obstacleDetected;
	}

	// Token: 0x060013D9 RID: 5081 RVA: 0x0008443B File Offset: 0x0008263B
	public override Vector3 GetPoint()
	{
		return this.point;
	}

	// Token: 0x060013DA RID: 5082 RVA: 0x00084443 File Offset: 0x00082643
	public override Vector3 GetNormal()
	{
		return this.normal;
	}

	// Token: 0x060013DB RID: 5083 RVA: 0x0008444C File Offset: 0x0008264C
	private bool DoRaycasts()
	{
		this.scale = this.myTransform.lossyScale.y;
		this.position = this.myTransform.position;
		this.walkingUp = (this.position.y > this.last_y + this.step * this.scale);
		this.last_y = this.position.y;
		this.up = this.myTransform.up;
		this.forward = this.myTransform.forward;
		return this.CheckForFalling() || this.CheckForWall();
	}

	// Token: 0x060013DC RID: 5084 RVA: 0x000844F4 File Offset: 0x000826F4
	private bool CheckForWall()
	{
		Vector3 vector = this.position + this.up * 1.4f * this.scale;
		Vector3 vector2 = this.forward;
		float num = this.wallDistance * this.scale;
		if (this.walkingUp)
		{
			num *= 0.3f;
		}
		if (this.debugRays)
		{
			Debug.DrawLine(vector, vector + vector2 * num, Color.white, this.timeBetweenChecks);
		}
		RaycastHit raycastHit;
		if (Physics.Raycast(vector, vector2, out raycastHit, num))
		{
			this.point = raycastHit.point;
			this.normal = raycastHit.normal;
			return true;
		}
		return false;
	}

	// Token: 0x060013DD RID: 5085 RVA: 0x000845A8 File Offset: 0x000827A8
	private bool CheckForFalling()
	{
		Vector3 vector = this.position + (this.up * 1.6f + this.forward * 1f) * this.scale;
		Vector3 vector2 = this.forward - this.up * 1.2f;
		float num = 4f * this.scale;
		if (this.debugRays)
		{
			Debug.DrawLine(vector, vector + vector2 * num, Color.white, this.timeBetweenChecks);
		}
		if (Physics.Raycast(vector, vector2, num))
		{
			return false;
		}
		this.point = vector + vector2 * num;
		this.normal = -this.forward;
		return true;
	}

	// Token: 0x04001713 RID: 5907
	private Vector3 point;

	// Token: 0x04001714 RID: 5908
	private Vector3 normal;

	// Token: 0x04001715 RID: 5909
	private float scale;

	// Token: 0x04001716 RID: 5910
	private float nextCheck;

	// Token: 0x04001717 RID: 5911
	private float timeBetweenChecks = 0.5f;

	// Token: 0x04001718 RID: 5912
	private bool obstacleDetected;

	// Token: 0x04001719 RID: 5913
	public bool debugRays = true;

	// Token: 0x0400171A RID: 5914
	private Transform myTransform;

	// Token: 0x0400171B RID: 5915
	private Vector3 position;

	// Token: 0x0400171C RID: 5916
	private Vector3 up;

	// Token: 0x0400171D RID: 5917
	private Vector3 forward;

	// Token: 0x0400171E RID: 5918
	private float wallDistance = 2.5f;

	// Token: 0x0400171F RID: 5919
	private bool walkingUp;

	// Token: 0x04001720 RID: 5920
	private float last_y;

	// Token: 0x04001721 RID: 5921
	private float step = 0.05f;
}
